/*工资查询*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:frametrim/activity/salaryDetailPage.dart';
import 'package:frametrim/app/app_navigator.dart';
import 'package:frametrim/listeners/OnDialogClickListener.dart';
import 'package:frametrim/utility/pickerDialogs.dart';
import 'package:frametrim/utility/screen.dart';
import 'package:frametrim/utility/sq_color.dart';
import 'package:frametrim/utility/timeUtil.dart';
import 'package:frametrim/views/appbar_black.dart';

class SalaryQueryPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => SalaryQueryState();
}

class SalaryQueryState extends State<SalaryQueryPage> {
  late String mYear = TimeUtil.getYear().toString();
  late OnDialogClickListener onPress;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: AnnotatedRegion(
        value: SystemUiOverlayStyle.light,
        child: Stack(
          children: <Widget>[
            Container(
              decoration: BoxDecoration(
                  /*设置渐变*/
                  gradient: LinearGradient(
                      /*默认渐变方向是从左往右，使用begin+end设置为需要的方向*/
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                      colors: [
                    Color(0xff3D8AFF),
                    Color(0xff1673FA),
                  ])),
              height: 280,
              width: Screen.width,
              // color: Color(0xff3D8AFF),
            ),
            Column(
              children: [
                AppbarCenterTitle(
                  title: '工资查询',
                  imgStr: 'image/imv_back_white.png',
                  titleColor: SQColor.white,
                ),
                SizedBox(
                  height: 15,
                ),
                buildHeader(),
                SizedBox(
                  height: 10,
                ),
                Expanded(
                  child: buildList(),
                )
              ],
            ),
          ],
        ),
      ),
    );
  }

  Widget buildHeader() {
    return Container(
      padding: EdgeInsets.all(10),
      width: Screen.width,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            '工资明细表',
            style: TextStyle(fontSize: 20, color: SQColor.white),
          ),
          Row(
            children: <Widget>[
              Expanded(
                child: Text(
                  '${mYear}年',
                  style: TextStyle(
                      fontSize: 44,
                      color: SQColor.white,
                      fontWeight: FontWeight.bold),
                ),
              ),
              GestureDetector(
                  onTap: () {
                    PickerDialogs.showYearPicker(context, '选择时间', (result) {
                      setState(() {
                        mYear=result.year.toString();
                      });
                    });
                  },
                  child: Container(
                    height: 40,
                    padding: EdgeInsets.only(left: 15, right: 15),
                    decoration: ShapeDecoration(
                        color: SQColor.color_151515,
                        shape: RoundedRectangleBorder(
                            borderRadius:
                                BorderRadius.all(Radius.circular(20)))),
                    child: Row(
                      children: <Widget>[
                        Text(
                          '${mYear}年',
                          style: TextStyle(fontSize: 20, color: SQColor.white),
                        ),
                        SizedBox(
                          width: 15,
                        ),
                        Image.asset(
                          'image/imv_down.png',
                          width: 13.03,
                          height: 7.81,
                        ),
                      ],
                    ),
                  )),
              SizedBox(
                width: 22,
              )
            ],
          ),
        ],
      ),
    );
  }

  /*下部工资列表*/
  Widget buildList() {
    return MediaQuery.removePadding(
      context: context,
      child: ListView.builder(
        itemBuilder: (context, index) {
          return buildSalaryMonth();
        },
        itemCount: 3,
      ),
      removeTop: true,
    );
  }

  Widget buildSalaryMonth() {
    return Container(
      padding: EdgeInsets.only(left: 10, right: 10),
      margin: EdgeInsets.only(left: 10, right: 10, bottom: 10),
      decoration: ShapeDecoration(
          color: Colors.white,
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(4)))),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            '8月份工资',
            style: TextStyle(
                fontSize: 24,
                color: SQColor.black,
                fontWeight: FontWeight.bold),
          ),
          Column(
            children: buildSarylyDay(),
          ),
        ],
      ),
    );
  }

  List<Widget> buildSarylyDay() {
    List<Widget> children = [];
    children.add(buildDay());
    children.add(Divider(
      height: 1,
      color: SQColor.color_E4E4E4,
    ));
    children.add(buildDay());
    return children;
  }

  Widget buildDay() {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: (){
        AppNavigator.push(context, SalaryDetailsPage(''));
      },
      child: Container(
        padding: EdgeInsets.only(top: 10, bottom: 15),
        child: Row(
          children: <Widget>[
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Container(
                        width: 18,
                        height: 18,
                        // color: SQColor.color_1773FA,
                        decoration: BoxDecoration(
                            color: SQColor.color_1773FA,
                            borderRadius: BorderRadius.all(
                              Radius.circular(9),
                            )),
                      ),
                      SizedBox(
                        width: 10,
                      ),
                      Text(
                        '8月15日',
                        style:
                        TextStyle(fontSize: 20, color: SQColor.color_222222),
                      )
                    ],
                  ),
                  SizedBox(
                    height: 6,
                  ),
                  Text(
                    '二七华侨城一号院',
                    style: TextStyle(fontSize: 14, color: SQColor.color_666666),
                  )
                ],
              ),
            ),
            Text(
              '¥ 7890.90',
              style: TextStyle(
                  fontSize: 24,
                  color: SQColor.color_222222,
                  fontWeight: FontWeight.bold),
            ),
          ],
        ),
      ),
    );
  }
}
